package com.rykj.energy.database.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.rykj.energy.common.enums.StateType;
import com.rykj.energy.database.mapper.DataDictAttrMapper;
import com.rykj.energy.database.pojo.BasicDataDictAttr;
import com.rykj.energy.database.service.IDataDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("dataDiceService")
public class DataDiceServiceImpl implements IDataDictService {

    @Autowired
    private DataDictAttrMapper dictAttrMapper;

    private static String systemCode = null;
    /**
     * 根据编号获取所有
     */
    @Override
    public List<BasicDataDictAttr> findAllByDictNum(String dictNum) {
        Map<String,Object> clomMap =new HashMap<>();
        clomMap.put("dictNum",dictNum);
        clomMap.put("status", StateType.NORMAL.getCode());
        return dictAttrMapper.selectByMap(clomMap);
    }

    /**
     * 获取所有
     */
    @Override
    public List<BasicDataDictAttr> findAllDict() {
        Map<String,Object> clomMap =new HashMap<>();
        clomMap.put("status", StateType.NORMAL.getCode());
        return dictAttrMapper.selectByMap(clomMap);
    }



    @Override
    public Map<String,Object> findBaseInfo(){
        List<BasicDataDictAttr> userTypes = findAllByDictNum("150000");
//        List<BasicDataDictAttr> orgTypes = dataDictAttrRepository.findAllByDictNum("260000");
        List<BasicDataDictAttr> webs = findAllByDictNum("250000");
        String webTitle = null;
        String webHelloWord = null;
        if(CollectionUtils.isNotEmpty(webs)){
            for (BasicDataDictAttr attr : webs){
                if(attr.getEngName().equals("webTitle")){
                    webTitle = attr.getDataName();
                }else if(attr.getEngName().equals("webHelloWord")){
                    webHelloWord = attr.getDataName();
                }
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("webTitle",webTitle);
        map.put("webHelloWord",webHelloWord);
        map.put("userTypes",userTypes);
//        map.put("orgTypes",orgTypes);
        return map;
    }

    @Override
    public void updateDataDictAttr(BasicDataDictAttr dataDictAttr) {
        BasicDataDictAttr oldDictAttr =  dictAttrMapper.selectById(dataDictAttr.getId());
        oldDictAttr.setRemark(dataDictAttr.getRemark());
        dictAttrMapper.updateById(oldDictAttr);
    }


}
